package com.wyz.controller;

import com.github.pagehelper.PageInfo;
import com.wyz.entity.Student;
import com.wyz.entity.Titletable;
import com.wyz.service.GradesService;
import com.wyz.service.TestPaperService;
import com.wyz.service.TitletableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
@Controller
public class TestPaper {
    @Autowired
    TitletableService titletableService;
    @Autowired
    GradesService gradesService;
    @RequestMapping("PaperSeach")
    public String seach(String name, String flag, Model model, String grade, @RequestParam(defaultValue = "1") int indexPage, HttpSession session){
        if (name!=null) {
            session.setAttribute("Titlename", name);
        }
        if (grade!=null){
            session.setAttribute("Titleclass",grade);
        }
        model.addAttribute("class",session.getAttribute("Titleclass"));
        model.addAttribute("name",session.getAttribute("Titlename"));
        PageInfo<Titletable> pageInfo = titletableService.findAll( session.getAttribute("Titleclass")==null ? "":session.getAttribute("Titleclass").toString(),session.getAttribute("Titlename")==null ? "":session.getAttribute("Titlename").toString(),indexPage, 5);
        model.addAttribute("grades",gradesService.findAll());
        model.addAttribute("pageInfo",pageInfo);
        return "insertTestPaper";
    }
}
